import React,{Suspense} from 'react'
import './App.scss'
import history from 'utils/history.js'
import PrivateRoute from 'components/PrivateRoute'

// 导入路由
import { Router, Route, Switch, Redirect } from 'react-router-dom'

// 导入组件
// import Layout from './pages/Layout'
// import Login from './pages/Login'
// import { hasToken } from 'utils/auth'
const Login = React.lazy(() => import('./pages/Login'));
const Layout = React.lazy(() => import('./pages/Layout'));

function App() {
  return (
		<Router history={history}>
			<div className="App">
				{/* 路由规则 */}
				<Suspense fallback={<div>loading...</div>}>
					<Switch>
						{/* 重定向 */}
						<Redirect exact from="/" to="/home"></Redirect>

						{/* 动态路由＋权限设置 */}
						<PrivateRoute path="/home" component={Layout} />
						{/* 
          <Route
            path="/home"
            render={(routeProps) => {
              // console.log(routeProps)

              if (hasToken()) {
                return <Layout {...routeProps} />
              } else {
                return <Redirect to="/login" />
              }
            }}
          /> */}
						<Route path="/login" component={Login}></Route>
						{/* <Route
            path="/login"
            render={(prop) => {
              return <Login {...prop} />
            }}
          /> */}
					</Switch>
				</Suspense>
			</div>
		</Router>
	);
}

export default App
